package com.zretc.kscxmz.controller;


import com.zretc.kscxmz.entity.Clock;
import com.zretc.kscxmz.services.ClockService;
import com.zretc.kscxmz.services.impl.ClockServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/Clock")
public class ClockController {
    private static final Logger logger = LoggerFactory.getLogger(DeptController.class);

    @Autowired
    private ClockService clockService;

    @RequestMapping("/getWorkStatusByid")
    @ResponseBody
    public ResponseEntity getCompanyById(@RequestParam(value = "accountId")int accountId,
                                         @RequestParam(value = "workTime")String workTime){
        logger.info("=====通过用户ID查询打卡信息======");
        logger.info("====accountId:"    + accountId);
        logger.info("====workTime:"  + workTime);

        //调用业务层
        String newWorkTime = "%" + workTime + "%";
        String workStatusByid = clockService.getWorkStatusByid(accountId,newWorkTime);
        logger.info("====getWorkStatusByid:"   + workStatusByid);
        if(workStatusByid !=null && workStatusByid.length()!=0){
            return  new ResponseEntity(workStatusByid,HttpStatus.OK);
        }
        return new ResponseEntity(null, HttpStatus.NO_CONTENT);
    }

    /*@RequestMapping("/getWorkTimesByid")
    public @ResponseBody
    String getWorkTimesByid(@RequestParam(value = "accountId")int accountId){
        logger.info("=====通过用户ID查询打卡信息======");
        logger.info("====accountId:"    + accountId);

        //调用业务层
        String workStatusByid = clockService.getWorkTimesByid(accountId);
        logger.info("====getWorkTimesByid:"   + workStatusByid);
        return workStatusByid;
    }*/

    @RequestMapping("/addWorkInfo")
    public @ResponseBody
    int addWorkInfo(@RequestParam(value = "accountId")int accountId,
                    @RequestParam(value = "address")String address,
                    @RequestParam(value = "workStatus")String workStatus,
                    @RequestParam(value = "workTime")String workTime){
        logger.info("=====通过部门ID修改部门信息======");
        logger.info("====deptName:"  + accountId);
        logger.info("====deptId:"    + address);
        logger.info("====email:"  + workStatus);
        logger.info("====deptAddr:"    + workTime);

        //调用业务层
        Map<String, Object> map = new HashMap<>();
        map.put("accountId",accountId);
        map.put("address",address);
        map.put("workStatus",workStatus);
        map.put("workTime",workTime);
        int companyByPage = clockService.addWorkInfo(map);
        logger.info("====clockService:"   + companyByPage);
        return companyByPage;
    }



    @RequestMapping("/getAllWorkStatusByid")
    @ResponseBody
    public ResponseEntity getAllWorkStatusByid(@RequestParam(value = "accountId")int accountId){
        logger.info("=====通过用户ID查询打卡信息======");
        logger.info("====accountId:"    + accountId);

        //调用业务层
        List<Clock> allWorkStatusByid = clockService.getAllWorkStatusByid(accountId);
        logger.info("====allWorkStatusByid:"   + allWorkStatusByid);
        if(allWorkStatusByid !=null && allWorkStatusByid.size()!=0){
            return  new ResponseEntity(allWorkStatusByid,HttpStatus.OK);
        }
        return new ResponseEntity(null, HttpStatus.NO_CONTENT);
    }
}
